﻿using System.Configuration;
using log4net.Core;

/*
 *  author: able
 *  @2012/2/25 23:48:46
 * 
 */
namespace __ts.Core.Util
{
    sealed class Settings : ConfigurationSection
    {
        private const string NAME = "Settings";

        [ConfigurationProperty("ArgsCapacity", DefaultValue = 1000)]
        public int ArgsCapacity
        {
            get { return (int)this["ArgsCapacity"]; }
        }

        [ConfigurationProperty("LogLevel", DefaultValue = "Info")]
        private string LogLevel
        {
            get { return (string)this["LogLevel"]; }
        }

        [ConfigurationProperty("LocalPort", DefaultValue = "8888")]
        public string LocalPort
        {
            get { return (string)this["LocalPort"]; }
        }

        public Level Level
        {
            get
            {
                switch (LogLevel)
                {
                    case "Info": return Level.Info;
                    case "Warn": return Level.Warn;
                    case "Error": return Level.Error;
                    default:
                        return null;
                }
            }
        }

        public static Settings Instance
        {
            get
            {
                Configurator<Settings> config = new Configurator<Settings>(NAME);
                return config.Load();
            }
        }
    }
}
